package boogui.member;

import java.util.Scanner;

import javax.swing.JOptionPane;

public class MemberService implements IMemberService {

	IMemberDAO mdao = null;
	IMemberLoginDAO mldao = null;

	public MemberService() {
		mdao = new MemberDAO();
		mldao = new MemberLoginDAO();
	}

	@Override
	public void createMember(MemberVO m) {
		if (mdao.insertMember(m))
			JOptionPane.showMessageDialog(null, "회원가입 되셨습니다.");
		else
			JOptionPane.showMessageDialog(null, "회원가입에 실패하였습니다.");
	}

	@Override
	public void readMember() {
		for (MemberVO m : mdao.selectMember()) {
			System.out.print(m.getMemno());
			System.out.print("/");
			System.out.print(m.getMemid());
			System.out.print("/");
			System.out.print(m.getMempwd());
			System.out.print("/");
			System.out.print(m.getMemname());
			System.out.print("/");
			System.out.print(m.getMembirth());
			System.out.print("/");
			System.out.print(m.getMemgenre());
			System.out.print("/");
			System.out.print(m.getMemhp());
			System.out.print("/");
			System.out.print(m.getMememail());
			System.out.println("/");
		}
	}

	@Override
	public void modifyMember(MemberVO m) {
		if (mdao.updateMember(m))
			JOptionPane.showMessageDialog(null, "수정성공");
		else
			JOptionPane.showMessageDialog(null, "수정실패");
	}

	@Override
	public void removeMember() {
		readMember();

		MemberVO mvo = new MemberVO();
		Scanner sc = new Scanner(System.in);
		System.out.println("삭제할 회원의 번호를 입력");
		mvo.setMemno(sc.next());

		if (mdao.deleteMember(mvo))
			System.out.println("회원 삭제 성공");
		else
			System.out.println("회원 삭제 실패");

	}

}
